<template>
  <login-com :config="config" @forgotPassword="forgotPassword" @loginSuccess="loginSuccess"/>
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import LoginCom from '@/components/login/index.vue'
import WPopView, { PopType } from '@/utils/popView'
import config from '@/project/admin/config'
import { isDev } from "@/config";
import { UserApi } from '@/api/apis'
import { post } from '@/api/ajax'

@Component({
  components: {
    LoginCom
  }
})
export default class Login extends Vue{
  /**
   * 配置数据
   */
  config = config

  loginSuccess() {
    this.$router.replace('/')
  }

  /**
   * 忘记密码
   */
  forgotPassword() {
    if (isDev) {
      WPopView.prompt('初始化密码', '请输入需要初始化的账号(超级管理员账号)', (text: string) => {
        if (text.length >= 4 && text.length <= 20) {
          return ''
        }
        return '请输入有效的账号'
      }).then((name: string) => {
        post(UserApi.resetPass, {
          name
        }).then(() => {
          WPopView.alert('初始化成功', '初始密码为【888888】', PopType.success)
        })
      })
    } else {
      WPopView.msgError('请联系其他管理员修改密码，或者在本地运行项目修改管理员密码')
    }
  }
}
</script>

<style scoped>

</style>
